package chpt11;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;

public class DatagramPacketTest {
	public static void main(String[] args) {
		String msg = "hello";
		try{
			byte[] data = msg.getBytes("UTF-8");
			InetAddress host = InetAddress.getByName("www.example.com");
			int port = 8192;
			DatagramPacket dp = new DatagramPacket(data,data.length,host,port);
			System.out.println("Host:"+dp.getAddress());
			System.out.println("Port:"+dp.getPort());
			System.out.println("Message:"+
			      new String(dp.getData(),dp.getOffset(),
			    		  dp.getLength(),"UTF-8"));
		}catch(IOException e){
			e.printStackTrace();
		}
	}
}
